<!DOCTYPE html>
<head>
	<% content_for :title, t("showBook") %>
	<script type='text/javascript'>
		//we pass id of star where mouse cursor is
		//and change class for every previous star
		function star(rate) {
			for (var i = 1; i <= rate; i++) {
				document.getElementById("rate_" + i).setAttribute("class", "staron");
			}
		}

		//we change class of all stars back to empty star
		function unstar(max) {
			for (var i = 1; i <= max; i++) {
				document.getElementById("rate_" + i).setAttribute("class", "staroff");
			}
		}

		function showrate(star, bookid) {
			window.location = "/book/showrate?star=" + star + "&book_id=" + bookid;
		}

		//generate stars
		//first param - amount of stars
		//second param - id of div where to attach stars
		function generate_stars(max, attach, bookid) {
			//get div container
			var container = document.getElementById(attach);
			for (var i = 1; i <= max; i++) {
				//create star
				var div = document.createElement("div");
				div.setAttribute("class", "staroff");
				div.setAttribute("id", "rate_" + i);
				//set events
				div.setAttribute("onmouseover", "star(" + i + ")");
				div.setAttribute("onmouseout", "unstar(" + max + ")");
				div.setAttribute("onclick", "showrate(" + i + "," + bookid + ")");
				//append child to contaner
				container.appendChild(div);
			}

		}
	</script>
</head>

<body id="book-cover">
	<div class="crumb_nav">
		<%if session[:language] == "vi"%>
			<a href="/homepage?lang=vi"><%= t :home %></a> &gt;&gt; <%= @book.title%>
		<%else%>
			<a href="/homepage"><%= t :home %></a> &gt;&gt; <%= @book.title%>
		<%end%>
	</div>
	<div class="title">
		<span class="title_icon"><img src="/bullet1.gif" alt="" title="" /></span><%= t :bookprofile %>
	</div>
	<div class="feat_prod_box_details">
		<div class="prod_img">
			<b>
			<p class="avatar">
				<%= t :bookavatar %>
			</p></b>
			<img src="<%= @book.image.url(:small) %>" alt="" title="" border="0" />
			<br />
			<br />
		</div>
		<div class="prod_det_box1">
			<b>
			<p class="avatar">
				<%= t :subdetails %>
			</p></b>
			<div class="box_top"></div>
			<div class="box_center">
				<div id="loginForm">
					<p id="notice">
						<%= notice %>
					</p>

					<div id="loginForm">
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :title%></b>
								<b><span class="profile_value"><%= @book.title %></span></b>
							</div>
						</p>
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :author%></b>
								<b><span class="profile_value"><%= @book.author %></span></b>
							</div>
						</p>
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :version%></b>
								<b><span class="profile_value"><%= @book.version %></span></b>
							</div>
						</p>
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :publisher%></b>
								<b><span class="profile_value"><%= @book.publisher %></span></b>
							</div>
						</p>
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :quantity %></b>
								<b><span class="profile_value"><%= @book.quantity %></span></b>
							</div>
						</p>
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :year%></b>
								<b><span class="profile_value"><%= @book.year %></span></b>
							</div>
						</p>
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :barcode%></b>
								<b><span class="profile_value"><%= @book.barcode %></span></b>
							</div>
						</p>
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :category %></b>
								<b><span class="profile_value"><%= @book.category %></span></b>
							</div>
						</p>
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :rate %></b>
								<b><span class="profile_value"><%= @book.rate %></span></b>
							</div>
						</p>
						<p>
							<div class="profile_row">
								<b class="profile"><%= t :description %></b>
								<b><span class="profile_value"><%= @book.description %></span></b>
							</div>
						</p>
						<br/>
						<% if session[:user] != nil%>
						<div class="profile_value">
							<div id='stars'></div>
						</div>
						<script type='text/javascript'>
							generate_stars(5, "stars", <%= @book.id %>
	);
						</script>
						<div>
							<%= form_tag('/book/request',:method => :post) do%>
							<input id="book_id" name="book[book_id]" type="hidden" value=<%= @book.id%>/>
							<div class="profile_row">
								<div class="profile_value">
									<input type="submit" class="register" value="<%= t :borrow %>" />
								</div>
							</div>
							<%end%>
						</div>
						<% end %>
						<br/>
						<br/>
						<%if session[:user].role == "admin"%>
						<div class="profile">
							<%if session[:language] == "vi"%>
								<strong class="changepass"><a href="<%= edit_book_path(@book)+"?lang=vi" %>" class = "changepass"><%= t :edit %></a></strong>
							<%else%>
								<strong class="changepass"><a href="<%= edit_book_path(@book) %>" class = "changepass"><%= t :edit %></a></strong>
							<%end%>
						</div>
						<%end%>
						<div class="profile">
							<%if session[:language] == "vi"%>
								<strong class="changepass"><a href="<%= books_path %>?lang=vi" class = "changepass"><%= t :back %></a></strong>
							<%else%>
								<strong class="changepass"><a href="<%= books_path %>" class = "changepass"><%= t :back %></a></strong>
							<%end%>
						</div>
						<br/>
					</div>
				</div>
			</div>
			<div class="box_bottom"></div>
			<br/>
			<br />

			<div>
				<% i=0%>
				<p>
					<strong><%= t :comment%></strong>
				</p>
				<%@comments.each do |comment|%>
				<div class="comment">
					<p>
						<%if session[:language] == "vi"%>
							<strong><a href='/user_profiles/<%= @profiles[i].id%>?lang=vi' ><%= @users[i].username%></a>:</strong>
						<%else%>
							<strong><a href='/user_profiles/<%= @profiles[i].id%>' ><%= @users[i].username%></a>:</strong>
						<%end%>
						<%= comment.content%>
						<br/>
						<%= comment.time_cm%>
					</p>
					<% i+=1%>
				</div>
				<% end %>
				<br/>
				<% if session[:user] != nil%>
				<%= form_tag('/book/comment',:method => :post) do%>
				<input id="book_id" name="book[book_id]" type="hidden" value=<%= @book.id%>/>
				<textarea id="comment" name="book[comment]" type="text" value="" ></textarea>
				<br/>
				<div class="comment_row">
					<input type="submit" class="register" value="<%= t :send %>" />

				</div>
				<%end%>
				<%end%>
			</div>

		</div>
		<div class="clear"></div>
	</div>
</body>
</html>

